#-*- coding: UTF-8 -*-
# from CCPRestSDK import
from .CCPRestSDK import REST


#主帐号
accountSid= '8a216da86488ce480164a1048d130a21'

#主帐号Token
accountToken= '577e9718df5e444e9225732171dee403'

#应用Id
appId='8a216da86488ce480164a1048d610a27'

#请求地址，格式如下，不需要写http://
serverIP='app.cloopen.com'

#请求端口
serverPort='8883'

#REST版本号
softVersion='2013-12-26'

  # 发送模板短信
  # @param to 手机号码
  # @param datas 内容数据 格式为数组 例如：{'12','34'}，如不需替换请填 ''
  # @param $tempId 模板Id






class CCP():
    """自己封装的发送短信验证码的辅助类"""
    # 实例对象
    instance = None
    def __new__(cls, *args, **kwargs):
        # 单例,保证每次初始化，只创建一个实例对象
        if cls.instance is None:
            obj = super(cls,CCP).__new__(cls)
            # 初始化REST SDK
            obj.rest = REST(serverIP, serverPort, softVersion)
            obj.rest.setAccount(accountSid, accountToken)
            obj.rest.setAppId(appId)

            cls.instance = obj

        return cls.instance

    # sendTemplateSMS(手机号码,内容数据,模板Id)
    def sendTemplateSMS(self,to, datas, tempId):

        try:
            result = self.rest.sendTemplateSMS(to, datas, tempId)
            print(result)
        except Exception as e:
            raise e
        status_code = result.get('statusCode')
        if status_code == '000000':
            return 0
        else:
            return -1



if __name__ == '__main__':
    ccp = CCP()
    ccp.sendTemplateSMS("13503998870", ["1234", 5], 1)

   
